package _7_io_socket_http.io;

import org.apache.commons.configuration.ConfigurationException;
import org.junit.Test;
import org.apache.commons.configuration.XMLConfiguration;

import java.nio.file.Path;
import java.nio.file.Paths;


/**
 * Created by bpzj on 4/28/2018.
 */
public class readXML {

    // 使用 apache commons configuration 读取 XML 文件
    // jar 包   commons-configuration
    //          commons-collections  两个

    @Test
    public void readXML() throws ConfigurationException {

        // 获取项目根路径 System.getProperty("user.dir")
        Path path = Paths.get(System.getProperty("user.dir"));
        System.out.println(path.toString());

        // 使用 resolve 组合路径
        String xmlFilePath = path.resolve("src/main/resources/cloudservice-conf.xml").toString();
        System.out.println(xmlFilePath);

        // 使用 apache configuration 读取xml配置文件，转为 XMLConfiguration
        XMLConfiguration conf = new XMLConfiguration(xmlFilePath);
        // 从 XMLConfiguration 中获取 xml 文件中某一个节点的值
        System.out.println(conf.getString("service.name"));
    }

}
